package Model;

/**
 * Classe modelo para o jogador.
 * Todas as informacoes referente ao jogador esta nesta classe.
 * 
 * @author Edjane Catolle, Igor Henrique, Luiz Augusto, Vladmir Chicarolli
 * @version 1.0.0
 * @since 06/05/2011
 */

import java.awt.Point;
import java.awt.Rectangle;

public class PlayerModel
{
	public static PlayerModel _player = null;
	private Point position;
	private Rectangle rectPreview;
	private Rectangle rectPlayer;
	private float speed;
	 
	private PlayerModel()
	{
		this.position = new Point(50, 50);		
		this.rectPlayer = new Rectangle(this.position.x, this.position.y, 50, 50);
		this.rectPreview = new Rectangle(this.position.x, this.position.y, 50, 50);
		this.speed = 10.0f;
	}
	
	public Point GetPosition()
	{
		return position;
	}

	/**
	 * Metodo utilizado para retorna a proxima posicao do jogador.
	 * Utilizado principalmente na colisao do jogado com os tiles bloqueados
	 * @return - retorno um retangulo com a proxima posicao do jogador.
	 */
	public Rectangle GetPreviewPosition()
	{
		return rectPreview;
	}
	
	public void SetPosition(Point position)
	{
		this.position = position;
	}
	
	/**
	 * Controla o movimento do jogador no eixo X
	 * @param direction - A direcao que o jogador vai mover. ESQUERDA < 0 > DIREITA.
	 */
	public void MoveX(int direction)
	{
		this.position.x += direction * speed;
		this.rectPlayer.x = this.position.x;
	}
	
	public void MovePreviewX(int direction)
	{
		this.rectPreview.x = this.position.x;
		this.rectPreview.y =  this.position.y;		
		this.rectPreview.x += direction * speed;		
	}
	
	/**
	 * Controla o movimento do jogador no eixo Y
	 * @param direction - A direcao que o jogador vai mover. CIMA < 0 > BAIXO.
	 */
	public void MoveY(int direction)
	{
		this.position.y += direction * speed;
		this.rectPlayer.y = this.position.y;
	}
	
	public void MovePreviewY(int direction)
	{
		this.rectPreview.x = this.position.x;
		this.rectPreview.y =  this.position.y;		
		this.rectPreview.y += direction * speed;
	}

	public Rectangle GetRectPlayer()
	{
		return rectPlayer;
	}

	public void SetRectPlayer(Rectangle rectPlayer)
	{
		this.rectPlayer = rectPlayer;
	}

	public float GetSpeed()
	{
		return speed;
	}

	public void SetSpeed(float speed)
	{
		this.speed = speed;
	}
	
	public static PlayerModel PlayerManager()
	{
		if(_player == null)
		{
			_player = new PlayerModel();
		}
		return _player;
	}
}
